<?php
session_start();
ob_start();
if (isset($_GET['lang'])) {

    $lang = $_GET['lang'];
} else {
    $lang = 'en';
}
include 'lang/' . $lang . '.php';
if (!isset($_SESSION['loggedin'])) {

    header('Location: login.php');
}
?>
<?php $id = $_GET['ID'];
$id_protected = htmlspecialchars($id);
?>
<?php $id = $_GET['ID'];
$id_protected = htmlspecialchars($id);
?>
<?php include 'index.php';
?>
<div id="body-wrapper">

    <div id="main-content">

        <div class="content-box">

            <?php
            include '../db/db_con.php';
            ?>
            <?php
            if (isset($_POST['updatenews'])) {

                
               if ($_FILES["photo_ar"]["name"] != "") {


        if ($_FILES["photo_ar"]["type"] == "image/gif" || $_FILES["photo_ar"]["type"] == "image/jpeg" || $_FILES["photo_ar"]["type"] == "image/jpg" || $_FILES["photo_ar"]["type"] == "image/pjpeg") {

            move_uploaded_file($_FILES["photo_ar"]["tmp_name"], "img/upload/" . $_FILES["photo_ar"]["name"]);

            $img = "img/upload/" . $_FILES["photo_ar"]["name"];
        }else{
            echo 'no '.mysql_error();
        }
    
      if ($_FILES["photo_en"]["name"] != "") {


        if ($_FILES["photo_en"]["type"] == "image/gif" || $_FILES["photo_en"]["type"] == "image/jpeg" || $_FILES["photo_en"]["type"] == "image/jpg" || $_FILES["photo_en"]["type"] == "image/pjpeg") {

            move_uploaded_file($_FILES["photo_en"]["tmp_name"], "img/upload/" . $_FILES["photo_en"]["name"]);

            $img_en = "img/upload/" . $_FILES["photo_en"]["name"];
        }else{
            echo 'no '.mysql_error();
        }
    }
               }        
                
                $query = "UPDATE news
            set img_ar = '{$img}',
            img_en = '{$img_en}'
            where id =".$id_protected." ";

                if (mysql_query($query)) {

                    echo '
		<div class="notification success png_bg">
				<a href="" class="close"><img src="resources/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>
				<div>
				This New Updated Is Done ..
				</div>
			</div>';
                } else {
                    echo '
		 <div class="notification error png_bg">
				<a href="" class="close"><img src="resources/images/icons/cross_grey_small.png" title="Close this notification" alt="close" /></a>
				<div>
				This New Updated Is Not Done ..
				</div>
			</div>';
                }
            }

            ?>


            <div class="content-box-header" id = "addProducts" >

                <h3>Update News</h3>



                <div class="clear"></div>

            </div> <!-- End .content-box-header -->

            <div class="content-box-content">


                <div class="tab-content default-tab" id="tab2">


                    <form action="update.php?type=News&ID=<?= $id_protected?>" method="post" name = "updatenews" enctype="multipart/form-data">

                        <fieldset> <!-- Set class to "column-left" or "column-right" on fieldsets to divide the form into columns -->

                            <p>
                                <label><?= News_Photo_ar ?></label>
                                <input class="text-input small-input" type="file" id="small-input" name="photo_ar" />
                            </p>

                            <p>
                                <label><?= News_Photo_en ?></label>
                                <input class="text-input small-input" type="file" id="small-input" name="photo_en" />
                            </p>

                          

                            <p>
                                <input class="button" type="submit" name = "updatenews" value="Update News" />
                            </p>

                        </fieldset>

                        <div class="clear"></div>

                    </form>

                </div>
            </div> 
        </div> 
    </div>
</div> 